package org.streets.context;

import java.io.Serializable;
/**
 * Main retrun value of the "streets" service call.
 *
 * @author Zenberg.D
 *
 */
public class ResultPack implements Serializable {
	/**
	 *
	 */
	private static final long serialVersionUID = -6128994708491838350L;
	/**
	 * Pack status failed value.
	 */
	public static final int FAILED	= -2;
    /**
	 * Pack status error value.
	 */
	public static final int ERROR   = -1;
	/**
	 * Pack status void value with a info result
	 */
	public static final int VOID 	=  0;
    /**
     * Pack status correct
     */
    public static final int CORRECT =  1;
	/**
	 * Pack status succeed value.
	 */
	public static final int SUCCEED =  2;
	/**
	 * Result pack status
	 */
	private int status = 0; // enum value in -2 -1 0 1 2
	/**
	 * Result pack message
	 */
	private String message = "";
	/**
	 * Result pack value
	 */
	private Object value = null;

	/**
	 * Get pack status value
	 * 
	 * @return
	 */
	public int getStatus() {
		return status;
	}
	/**
	 * Set packed status value
	 * @param status
	 */
	public void setStatus(int status) {
		this.status = status;
	}
	/**
	 * Get packed message
	 * 
	 * @return
	 */
	public String getMessage() {
		return message;
	}
	/**
	 * Set pack message
	 * @param message
	 */
	public void setMessage(String message) {
		this.message = message;
	}
	/**
	 * Get packed value
	 * @return
	 */
	public Object getValue() {
		return value;
	}
	/**
	 * Set packed value
	 * @param value
	 */
	public void setValue(Object value) {
		this.value = value;
	}

    public boolean isFailed() {
        return this.status == ResultPack.FAILED;
    }
    
    public boolean isError() {
        return this.status == ResultPack.ERROR;       
    }
    
    public boolean isCorrect() {
        return this.status == ResultPack.CORRECT;
    }
    
    public boolean isSucceed() {
        return this.status == ResultPack.SUCCEED;
    }

	@Override
	public String toString() {
		return (new StringBuilder("Status:[")).append(status).append("] Info:[").append(message).toString();
	}
	
    public ResultPack() {
        
    }
	/**
	 * Pack void result always packed with a message. 
	 * @return
	 */
	public static ResultPack packVoidResult() {
		ResultPack result = new ResultPack();
		result.status = ResultPack.VOID;
		return result;
	}
	/**
	 * Pack void result always packed with a message
	 * @param message
	 * @return
	 */
	public static ResultPack packVoidResult(String message) {
		ResultPack result = new ResultPack();
		result.status = ResultPack.VOID;
		result.message = message;
		return result;
	}	
	/**
	 * Pack when error occurs
	 * @param message 
	 * @return
	 */
	public static ResultPack packErrorResult(String message) {
		ResultPack result = new ResultPack();
		result.status = ResultPack.ERROR;
		result.message = message;
		return result;
	}
	/**
	 * Pack when error occurs
	 * @param message
	 * @param value always should be a Cause class
	 * @return
	 */
	public static ResultPack packErrorResult(String message, Object value) {
		ResultPack result = new ResultPack();
		result.status = ResultPack.ERROR;
		result.message = message;
		result.value = value;
		return result;
	}
	/**
	 * Pack when failed occurs
	 * @param message
	 * @return
	 */
	public static ResultPack packFailedResult(String message) {
		ResultPack result = new ResultPack();
		result.status = ResultPack.FAILED;
		result.message = message;
		return result;
	}
	/**
	 * Pack when failed occurs
	 * @param message
	 * @param value
	 * @return
	 */
	public static ResultPack packFailedResult(String message, Object value) {
		ResultPack result = new ResultPack();
		result.status = ResultPack.FAILED;
		result.message = message;
		result.value = value;
		return result;
	}

    public static ResultPack packCorrectResult() {
		ResultPack result = new ResultPack();
		result.status = ResultPack.CORRECT;
		return result;
    }

    public static ResultPack packCorrectResult(String message) {
        ResultPack result = new ResultPack();
        result.status = ResultPack.CORRECT;
        result.message = message;
		return result;
    }

    public static ResultPack packCorrectResult(String message, Object value) {
        ResultPack result = new ResultPack();
        result.status = ResultPack.CORRECT;
        result.message = message;
        result.value = value;
		return result;
    }
	/**
	 * Pack void result always packed with a message
	 * @param message
	 * @return
	 */
	public static ResultPack packSucceedResult(String message) {
		ResultPack result = new ResultPack();
		result.status = ResultPack.SUCCEED;
		result.message = message;
		return result;
	}

	public static ResultPack packSucceedResult(Object value) {
		ResultPack result = new ResultPack();
		result.status = ResultPack.SUCCEED;
		result.value = value;
		return result;
	}

	public static ResultPack packSucceedResult(String message, Object value) {
		ResultPack result = new ResultPack();
		result.status = ResultPack.SUCCEED;
		result.message = message;
		result.value = value;
		return result;
	}
}
